
# put your PETSC_xxx values here
PETSC_DIR=$(shell $(HOME)/bin/petscdir)
PETSC_ARCH=$(shell $(HOME)/bin/petscarch)

# put path to your Mesquite installation here
MESQUITE_DIR=$(HOME)

# put installation directory for soah3d executable here:
SOAH3D_INSTALL_DIR=$(HOME)/bin

# only modify the following if something is wrong, okay!
# ============================================================================

base_dir := ..
EXEFILE=$(base_dir)/../bin/regrid

include $(base_dir)/errlog/Makefile.vars
include $(base_dir)/grid3d/Makefile.vars
include $(base_dir)/common/Makefile.vars

# default target -- runs when no target is specified
all :: $(EXEFILE)

# this imports the PETSC makefile rules.
include $(PETSC_DIR)/conf/base

include $(base_dir)/errlog/Makefile.rulz
include $(base_dir)/grid3d/Makefile.rulz
include $(base_dir)/common/Makefile.rulz

# these variables are used to compile and link with Mesquite
INCLUDE_MESQUITE=-I$(MESQUITE_DIR)/include
LINK_MESQUITE=-L$(MESQUITE_DIR)/lib -lmesquite

# this file is automatically generated and contains dependency info
include Makefile.d

# hold-all include variable
ALL_INCLUDES = -I. -I$(GRID3D_DIR) -I$(COMMON_DIR) -I$(ERRLOG_DIR) $(INCLUDE_MESQUITE)

# use these flags with gcc
DEPGENFLAGS = -MM $(ALL_INCLUDES)
CFLAGS = -m64 -std=c99 -g $(ALL_INCLUDES)
CXXFLAGS = -m64 -g $(ALL_INCLUDES)
LDFLAGS = -m64 -lm -L$(base_dir)/../lib/ -lgrid3d -lcommon -lerrlog $(LINK_MESQUITE)

# use these flags with suncc
# DEPGENFLAGS = -xM1 $(INCLUDE_MESQUITE)
# CFLAGS = -m64 -xc99 -errfmt=error $(INCLUDE_MESQUITE)
# LDFLAGS = -m64 -lm $(LINK_MESQUITE)

# the source files are all *.c files in the current directory.
# if you have any .c files that are not part of the project, put them in
# a subdirectory.  Otherwise a compilation error in one of them ruin all.
# srcc = $(shell ls $(MY_SRCDIR)/*.c)
#srcc = $(shell ls *.c)
srccc = $(shell ls *.cc)

# every .c file produces a .o file with the same name, so
objs = $(srcc:.c=.o) $(srccc:.cc=.o)

# this copies the executable to $(HOME)/bin/
install : # $(EXEFILE)
	${CP} $(EXEFILE) $(SOAH3D_INSTALL_DIR)

# this links the executable
$(EXEFILE) : $(objs) $(GRID3D_LIB) $(COMMON_LIB) $(ERRLOG_LIB)
	${CXX} -o $@ $(objs) ${LDFLAGS} $(LOADLIBES) $(LDLIBS)


# this removes the executable and all .o object files
.PHONY : clean
clean ::
	-@${RM} $(objs)
	-@${RM} $(EXEFILE)

# this does clean + removes the executable from $(HOME)/bin as well
.PHONY : clean_install
clean_install :: clean
	-@${RM} $(SOAH3D_INSTALL_DIR)/$(EXEFILE)

# this generates dependency info
Makefile.d : $(srcc) $(srccc)
	$(CC) $(DEPGENFLAGS) $(srcc) $(srccc) > Makefile.d


